﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PPRecorder
{
    internal partial class InputForm : Form
    {
        #region Constructors

        /// <summary>
        /// Default constructor.
        /// </summary>
        internal InputForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Parameterized constructor.
        /// </summary>
        /// <param name="caption">Title for the Input form.</param>
        /// <param name="defaultValue">Default to be displayed in the textbox.</param>
        internal InputForm(string caption, string AuthorValue, string ProfileValue)
            : this()
        {
            this.Text = caption;
            profileValue.Text = AuthorValue;
            authorValue.Text = ProfileValue;
        }

        #endregion Constructors

        #region Public Properties

        /// <summary>
        /// Accessor for the textbox value.
        /// </summary>
        internal string AuthorValue
        {
            get { return profileValue.Text; }
            set { profileValue.Text = value; }
        }

        internal string ProfileValue
        {
            get { return authorValue.Text; }
            set { authorValue.Text = value; }
        }

        #endregion Public Properties

        private void InputForm_Load(object sender, EventArgs e)
        {
            this.profileValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckKeys);
            this.authorValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckKeys);
        }

        private void CheckKeys(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                if (authorValue.Text.Trim().Length != 0)
                {
                    if (profileValue.Text.Trim().Length != 0)
                    {
                        setProfileName.DialogResult = DialogResult.OK;
                        setProfileName.PerformClick();
                    }
                    MessageBox.Show("Please fill in the profile's name..", "Empty field detected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    profileValue.Focus();
                    return;
                }

                else
                {
                    MessageBox.Show("Please fill in your name..", "Empty field detected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
    }
}
